home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / bootup / boot_a2m / load_inf / load_inf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-02  |  2.7 KB  |  125 lines

  1. /********************************************\
  2. |** LOAD_INF.C is (c) Klaus Pedersen. 7/90 **|
  3. |** Written in Borland Turbo C v2.0        **|
  4. \********************************************/
  5.  
  6. #include <aes.h>
  7. #include <tos.h>
  8. #include <string.h>
  9.  
  10. #define _vTOS                 (_GemParBlk.global[0])
  11.  
  12. int MaxShell = 4192;
  13. char Buffer[4192];
  14.  
  15.  
  16.  
  17.  
  18. /************************************************\
  19. |*                FILE SELECT ROUTINE                         *|
  20. \************************************************/
  21. char *strRchr(char *path, char look)
  22. {char *cptr;
  23.     cptr = 0l;
  24.     while (*path)
  25.         if (*path++ == look) cptr = path-1;
  26.     if (cptr)
  27.         return cptr;
  28.     else
  29.         return path;
  30. }
  31.  
  32.  
  33. void BuildFName(char *path, char *fname, char look)
  34. {char *p;
  35.     if (*(p = strRchr(path, look)) != 0) p++;
  36.     strcpy(p, fname);
  37. }
  38.  
  39.  
  40. int ForceExt(char *path, char *ext)
  41. {char *ph;
  42.     ph = strRchr(strRchr(path, '\\'), '.');
  43.     strcpy(ph, ext);
  44.     return 0;
  45. }
  46.  
  47.  
  48. int FileSelect(char *Path, char *Mask, char *DefFile, char *Label)
  49. /*    File select : 
  50.  *     if Path[0] == '.' then on default path,
  51.  *            else on path in 'Path'...
  52.  *        if  DefFile[0] == '*' then take Default file name from Path...
  53.  * if TOS is higher than 1.2 then the Label can be used...  
  54.  * Returns : - Full file path in Path.
  55.  *           - 0 if no file has been selected...
  56.  * NOTE : 'Mask' must have a leading back-slash!
  57.  *        'DefFile' must be at least 13 bytes!
  58.  */
  59. {int  ok_bottn;
  60.  char *p;
  61.  
  62.     if (*DefFile == '*')
  63.     {    if (*(p = strRchr(Path, '\\')) != 0) p++;
  64.         strcpy(DefFile, p);
  65.     }
  66.     
  67.      if (*Path == '.')
  68.     {    Dgetpath(Path, 0);
  69.         strcat(Path, Mask);
  70.     }
  71.     else
  72.          BuildFName(Path, Mask+1, '\\');
  73.          
  74.     if (_vTOS < 0x130 || *Label == '\0')
  75.          fsel_input(Path, DefFile, &ok_bottn);
  76.     else
  77.         fsel_exinput(Path, DefFile, &ok_bottn, Label);
  78.         
  79.     if (ok_bottn)
  80.         BuildFName(Path, DefFile, '\\');
  81.     return ok_bottn;
  82. }
  83.  
  84.  
  85. main(int argc, const char *argv[])
  86. {char Path[128], *p;
  87.  const char *loadPath;
  88.  static char M[7] = "\\*.INF", F[13] = "DESKTOP.INF";
  89.  int f;
  90.  long l;
  91.  
  92.     appl_init();
  93.  
  94.     if (_vTOS < 0x130) MaxShell = 1024;
  95.         
  96.     if (argc <= 1)
  97.     {    *Path = '.'; /* Start the fileselect from default dir */
  98.         if ( !FileSelect(Path, M, F, "Select New Desk Config.") ) goto No_Load;
  99.         loadPath = Path; /* use name from file selector */
  100.     }
  101.     else /* use name from the command line */
  102.         loadPath = argv[1];
  103.         
  104.     
  105.     if ( (f = Fopen(loadPath, 0)) > 0 )
  106.     {    l = Fseek(0, f, 2); /* get length of file */
  107.         Fseek(0, f, 0);
  108.         if (l < MaxShell) /* will the file fit in the Shell buffer?*/
  109.         {    Fread(f, l, Buffer);
  110.             p = &Buffer[l]; /* insert a ^Z after the file */
  111.             *p++ = '\32';
  112.             l = MaxShell;
  113.             do 
  114.                 *p++ = 0;
  115.             while (--l);
  116.             shel_put(Buffer, MaxShell);
  117.         }
  118.         Fclose(f);
  119.     }
  120.  
  121. No_Load:
  122.     appl_exit();
  123.     return 0;
  124. }
  125.